package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.EmployeeLeave;
import com.amsp.oa.oademo.mapper.EmployeeLeaveMapper;
import com.amsp.oa.oademo.service.EmployeeLeaveService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class EmployeeLeaveServiceImpl extends ServiceImpl<EmployeeLeaveMapper, EmployeeLeave> implements EmployeeLeaveService {

    @Override
    public IPage<EmployeeLeave> getPage(Integer current, Integer size, String employeeName, String employeeId, String department) {
        LambdaQueryWrapper<EmployeeLeave> wrapper = new LambdaQueryWrapper<>();
        
        if (StringUtils.isNotBlank(employeeName)) {
            wrapper.like(EmployeeLeave::getEmployeeName, employeeName);
        }
        if (StringUtils.isNotBlank(employeeId)) {
            wrapper.like(EmployeeLeave::getEmployeeId, employeeId);
        }
        if (StringUtils.isNotBlank(department)) {
            wrapper.like(EmployeeLeave::getDepartment, department);
        }
        
        wrapper.orderByDesc(EmployeeLeave::getCreateTime);
        
        return page(new Page<>(current, size), wrapper);
    }
} 